<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list></city-list>
  </div>
</template>

<script>
  import CityHeader from './components/Header'
  import CitySearch from './components/Search'
  import CityList from './components/List'
  import SingleTree from './components/SingleTree'
  import GLOBAL from "@/api/global_variable"
  import axios from 'axios'
  export default {
    name: 'City',
    components: {
      CityHeader,
      CitySearch,
      CityList,
      SingleTree
    },
    data () {
      return {
        ip: GLOBAL.ip,
        userId: null,
        roleId: null,
        areaList:[],
        cities:[],
      }
    },
    mounted () {
      this.getAreaList();
      this.getCookie();
    },
    created() {
      // 获取链接参数值，然后存进内存中
      this.userId= this.$route.query.userId
    },
    methods: {
      //读取cookie
      getCookie: function() {
        if(document.cookie.length > 0) {
          var arr = document.cookie.split('; '); //这里显示的格式需要切割一下自己可输出看下
          for(var i = 0; i < arr.length; i++) {
            var arr2 = arr[i].split('='); //再次切割
            //判断查找相对应的值
            if(arr2[0] == 'userName') {
              this.userNameValue = arr2[1]; //保存到保存数据的地方
            } else if(arr2[0] == 'userPwd') {
              this.passWordValue = arr2[1];
            } else if(arr2[0] == 'userId') {
              this.userId = arr2[1];
            } else if(arr2[0] == 'roleId') {
              this.roleId = arr2[1];
            }
          }
        }
      },
      //获取区域列表；
      getAreaList: function(){
        axios.get(this.ip + '/api/elevator/area/list?operator_user_id=' + this.userId)
          .then(this.getAreaListDataSucc)
      },
      getAreaListDataSucc: function(res) {
        //console.log(res.data.area_list)
        this.areaList = res.data.area_list
        //console.log(this.areaList)
        for(var i = 0 ; i < res.data.area_list[0].nodes.length; i++){
          this.cities.push({text:res.data.area_list[0].nodes[i].text, id:res.data.area_list[0].nodes[i].area_id})
        }
        console.log(this.cities)
      },
    },
  }
</script>

<style lang="stylus" scoped="scoped">

</style>
